<?php
    /**
     * Created by PhpStorm.
     * User: mybook-lhp
     * Date: 18/10/22
     * Time: 上午10:20
     */

    namespace app\payment\logic;


    use think\Db;

    class Pay implements PayInterFace
    {

        static $object = null;

        protected $pay = null;

        static public function Init($pay)
        {

            if (self::$object === null)
            {
                self::$object = new static($pay);
            }
            return self::$object;
        }

        protected function __construct($pay)
        {

            $this->pay = $pay;
        }

        public function create_order($data)
        {

            return $this->pay->create_order($data);
        }

        public function send($out_trade_no,$total_fee,$pay_point)
        {

            return $this->pay->send($out_trade_no,$total_fee,$pay_point);
        }

        public function transaction($data)
        {

            try
            {
                Db::startTrans();

                $this->pay->transaction($data);
                Db::commit();
                return ['code' => 200,'msg' => '支付成功！','data' => []];
            }
            catch (\Exception $exception)
            {
                Db::rollback();
                return ['code' => 500,'msg' => '支付失败！','data' => []];
            }
        }
    }